
//{promotionids:[1,2,3]}
var Cart = {	
	add_number : function(pid,skuid,count,promoationids,serviceids,typeid,callback){
		promoationids = promoationids || [];
		serviceids = serviceids || [];
		typeid = typeid || 0;
		var cookie_value = getcookie('source_cid'); // 读取 cookie
		if(cookie_value == 'sqgc1303' ){
			Cart.addcountnumber(count);
		}
		$.ajax({
			url: HOST + "/store/cart/add_count.jhtml",
			type: "POST",
			data: {
				productid:pid,
				skuid:skuid,
				count:count,
				promotionids: promoationids.join(),
				serviceids:serviceids.join(),
				typeid: typeid
			},
			dataType: "json",
			cache: false,
			success: function(message) {
					Common.processCart();
					if(!callback)
					{
						alert(message.type);
					}
					else
					{
						callback(message);
					}
			}
		});
	},
	buy_now : function(promoationids,serviceids){
		var cookie_value= getcookie("SHOP_account");
		cookie_value = cookie_value || "";
		cookie_value = cookie_value.replace("\"","");
		if(cookie_value == null || "" == cookie_value || "null" == cookie_value){
			$("#buy-goods").removeClass("disabled");
			loginiframe();
		} else {
			promoationids = promoationids || [];
			serviceids = serviceids || [];
			$("#buyNow #spids").val(promoationids.join());
			$("#buyNow #serviceid").val(serviceids.join());
			$("#buyNow").submit();
		}
	},
	add : function(pid,skuid,count,callback){
		$.ajax({
			url: HOST + "/store/cart/add.jhtml",
			type: "POST",
			data: {
				productid:pid,
				skuid:skuid,
				count:count
			},
			dataType: "json",
			cache: false,
			success: function(message) {
					if(!callback)
					{
						alert(message.type);
					}
					else
					{
						callback(message);
					}
			}
		});
	},
	remove : function(pid,skuid,count,skuname,dataprice,skunumber,categoryid,categoryname,callback){
		var cookie_value = getcookie('source_cid'); // 读取 cookie
		if(cookie_value == 'sqgc1303' ){
			Cart.removecount(count,skuname,dataprice,skunumber,categoryid,categoryname);
		}
		$.ajax({
			url: HOST + "/store/cart/remove.jhtml",
			type: "POST",
			data: {
				productid:pid,
				skuid:skuid
			},
			dataType: "json",
			cache: false,
			success: function(message) {
					if(!callback)
					{
						alert(message.type);
					}
					else
					{
						callback(message);
					}
			}
		});
		
	},
	
	addcountnumber : function (count){
		var account = $("#account").val();
		var skucode = $("#skucode").val();
		var price = $("#price").val();
		var name = $("#skuname").val();
		var categoryid = $("#categoryid").val();
		var categoryname = $("#categoryname").val();
		_adwq.push([ '_setDataType', 
		             'cart' // 指定数据类型为加入购物车 - 固定值 - 必填项
		             ]); 
		             _adwq.push([ '_setCustomer', 
		                          account // 请输入用户会员ID或用户名 
		             ]); 

		             // 如果一次性可以将多个商品加入购物车请写多次_setItem
		             _adwq.push(['_setItem', 
		             skucode, // 请填入商品编号 - 必填项 
		             name, // 请填入商品名称 - 必填项 
		             price, // 请填入商品金额 - 必填项 
		             count, // 请填入商品数量 - 必填项 
		             categoryid, // 请填入商品分类编号 - 必填项 
		             categoryname // 请填入商品分类名称 - 必填项 
		             ]);
		             _adwq.push([ '_trackTrans' ]); // 触发加入购物车数据提交 - 固定值 - 必填项
//		             alert("account="+account+"skucode="+skucode+"name="+name+"price="+price+"count="+count+"categoryid="+categoryid+"categoryname="+categoryname);

	},
	removecount : function (count,skuname,dataprice,skunumber,categoryid,categoryname){
		var account = $("#account").val();
		
		_adwq.push([ '_setDataType', 
		             'delete' // 指定数据类型为删除购物车 - 固定值 - 必填项
		             ]); 

		             _adwq.push([ '_setCustomer', 
		                          account // 请输入用户会员ID或用户名 
		             ]); 

		             _adwq.push(['_setItem', 
		                     skunumber, // 请填入商品编号 - 必填项 
	                         skuname, // 请填入商品名称 - 必填项 
	                         dataprice, // 请填入商品金额 - 必填项 
	                         count, // 请填入商品数量 - 必填项 
	                         categoryid, // 请填入商品分类编号 - 必填项 
	                         categoryname // 请填入商品分类名称 - 必填项 
		             ]); 
		             _adwq.push([ '_trackTrans' ]); // 触发删除购物车数据提交 - 固定值 - 必填项
//		             alert("account="+account+"skucode="+skunumber+"name="+skuname+"price="+dataprice+"count="+count+"categoryid="+categoryid+"categoryname="+categoryname);
		            // alert(_adwq);

	}
}
